// pages/per_info/deposit/index.js
import Common from '../../../utils/common.js'
let http = new Common()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    aaindex:null
  },
  click:function(e){
    this.setData({
      aaindex:e.currentTarget.dataset.index
    })
  },
  adds:function(){
    let that = this
    let index = this.data.aaindex
    if (index != null){
      let data = {
        viptel: this.data.tel,
        rechargeid: that.data.info[index].id,
        olPrice: that.data.info[index].olPrice,
        kqPrice: that.data.info[index].kqPrice,
      }
      http.http({
        url: "mp2/store/getrechargeurl",
        data: data,
        success(res) {
          let payURL = res.data.data.payUrl
          if (payURL) {
            wx.requestPayment({
              timeStamp: payURL.timeStamp,
              nonceStr: payURL.nonceStr,
              paySign: payURL.paySign,
              signType: payURL.signType,
              package: payURL.package,
              complete(res) {
                http.goUrl({
                  method: 'switchTab',
                  url: `../lists/index`
                })
              }
            })
          } 
        }
      })
    }else{
      wx.showModal({
        content: '请选择充值模式',
      })
    }
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    let data = JSON.parse(options.data)
    let tel = wx.getStorageSync('tel')

    this.setData({
      info: data.recharges,
      tel: tel
    })
    
    console.log(this.data.info)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})